//
//  LoginView.m
//  WULIHH
//
//  Created by tang on 16/4/12.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "LoginView.h"
#import "Header.h"
#import "UMSocial.h"

@implementation LoginView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *image = nil;
        
        image = [UIImage imageNamed:@"background.png"];
        UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WithView, heightView)];
        [self addSubview:backImageView];
        [backImageView setImage:image];
        
        image = [UIImage imageNamed:@"wechatdenglu"];
        UIButton *wechatimageView = [[UIButton alloc] initWithFrame:CGRectMake((WithView-image.size.width)/2.0, 211.0, image.size.width, image.size.height)];
        [wechatimageView setBackgroundImage:image forState:UIControlStateNormal];
        [self addSubview:wechatimageView];
        
        image = [UIImage imageNamed:@"qqdenglu"];
        UIButton *qqimageView = [[UIButton alloc] initWithFrame:CGRectMake((WithView-image.size.width)/2.0, CGRectGetMaxY(wechatimageView.frame)+14.0, image.size.width, image.size.height)];
        [qqimageView setBackgroundImage:image forState:UIControlStateNormal];
        [self addSubview:qqimageView];

        image = [UIImage imageNamed:@"xinlangdenglu"];
        UIButton *sinaimageView = [[UIButton alloc] initWithFrame:CGRectMake((WithView-image.size.width)/2.0, CGRectGetMaxY(qqimageView.frame)+15.0, image.size.width, image.size.height)];
        [sinaimageView setImage:image forState:UIControlStateNormal];
        [self addSubview:sinaimageView];

        
        [wechatimageView setTag:1];
        [qqimageView setTag:2];
        [sinaimageView setTag:3];
        
        [wechatimageView addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
        [qqimageView addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
        [sinaimageView addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
        
        
//        [self initWithUI];
    }
    return self;
}


- (void)initWithUI
{
    
}





- (void)loginButton:(UIButton *)sender
{
    if (sender.tag == 1)
    {
        UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
        
        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
            
            //          获取微博用户名、uid、token等
            
            if (response.responseCode == UMSResponseCodeSuccess) {
                
                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
                
                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
                
            }});
    }
    else if (sender.tag == 2)
    {
        
    }
    else if (sender.tag == 3)
    {
        
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
